package com.chaos.auth.service.client;


import com.chaos.auth.api.feign.Oauth2Feign;
import com.chaos.framework.model.dto.result.data.DataResult;
import com.chaos.framework.starter.base.BaseController;
import io.swagger.v3.oas.annotations.Hidden;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author jacky
 * @since 2025-04-21
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@Hidden
public class Oauth2Client extends BaseController implements Oauth2Feign {


    // private final Oauth2RegisteredClientMapper oauth2RegisteredClientMapper;
    private final PasswordEncoder passwordEncoder;

    //    @Override
    //    @PostMapping("/add")
    //    public DataResult add(Oauth2RegisteredClientData data) {
    //        SelfOauth2RegisteredClient client = new SelfOauth2RegisteredClient();
    //        client.setId(UUID.randomUUID().toString());
    //        client.setClientId("oidc-client");
    //        client.setClientSecret("{noop}secret");
    //        client.setClientName("oidc-client");
    //        Set<ClientAuthenticationMethod> methodSet = new HashSet<>();
    //        client.setClientAuthenticationMethods(new HashSet<>(Collections.singleton(ClientAuthenticationMethod.CLIENT_SECRET_BASIC.getValue())));
    //        Set<String> typeSet = new HashSet<>();
    //        typeSet.add(AuthorizationGrantType.AUTHORIZATION_CODE.getValue());
    //        typeSet.add(AuthorizationGrantType.REFRESH_TOKEN.getValue());
    //        client.setAuthorizationGrantTypes(typeSet);
    //        client.setRedirectUris(new HashSet<>(Collections.singleton("http://localhost:8080/login/oauth2/code/oidc" +
    //                "-client")));
    //        client.setPostLogoutRedirectUris(new HashSet<>(Collections.singleton("http://localhost:8080/")));
    //        Set<String> scopeSet = new HashSet<>();
    //        scopeSet.add(OidcScopes.OPENID);
    //        scopeSet.add(OidcScopes.PROFILE);
    //        client.setScopes(scopeSet);
    //        client.setClientSettings(ClientSettings.builder().requireAuthorizationConsent(true).build());
    //        client.setTokenSettings(TokenSettings.builder().build());
    //
    //
    //        //oauth2RegisteredClientMapper.insert(client);
    //        System.out.println(client);
    //        return null;
    //    }

    @Override
    public DataResult<String> passwordEncoder(String password) {
        return dataResult(passwordEncoder.encode(password));
    }


}
